package com.lixunhuan.handacount.db.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lixunhuan.handacount.db.bean.HandAcount;
import com.lixunhuan.handacount.vo.HandAcountVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author lixunhuan
 * @since 2021-03-19
 */
public interface HandAcountMapper extends BaseMapper<HandAcount> {

    @Select("SELECT LEFT(add_time,10)as date FROM hand_acount where type =#{type} and uid=#{uid} GROUP BY LEFT(add_time,10) ORDER BY id desc")
    List<String> dateList(@Param("type") Integer type, @Param("uid") String uid);

    @Select("SELECT SUM(amount) FROM hand_acount where type =#{type} and uid=#{uid} and LEFT(add_time,10)=#{date}")
    Double total(@Param("date") String date, @Param("type") Integer type, @Param("uid") String uid);


    @Select("SELECT\n" +
            "\tha.*,\n" +
            "\tk.descstr AS icondesc,\n" +
            "\tk.iconstr \n" +
            "FROM\n" +
            "\thand_acount ha\n" +
            "\tLEFT JOIN kind k ON ha.kind_id = k.id \n" +
            "WHERE\n" +
            "\tha.type = #{type} \n" +
            "\tAND LEFT ( ha.add_time, 10 ) = #{date} AND ha.uid = #{uid}")
    List<HandAcountVo> getHandAcountListsByDetail(@Param("date") String date, @Param("type") Integer type, @Param("uid") String uid);
}
